/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.pbp.model;

import ac.pbp.core.util.MyValidator;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;

@Entity
@Table(name = "buku_user")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class BukuUser implements Serializable {

    @EmbeddedId
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private BukuUserPK bukuUserPk;
    
    @Column(name = "tanggal_status_buku")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date tanggal_status_buku;
    
    @Column(name = "status_buku")
    private String statusBuku;
    
    @Column(name = "rating_buku")
    private Integer ratingBuku;
    
    @Column(name = "isi_review_buku")
    private String reviewBuku;
    
    @Column(name = "tanggal_review_buku")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date tanggalReviewBuku;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "kode_user", insertable = false, updatable = false)
    @LazyToOne(LazyToOneOption.NO_PROXY)
    @Fetch(FetchMode.SELECT)
    private User user;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "kode_buku", insertable = false, updatable = false)
    @LazyToOne(LazyToOneOption.NO_PROXY)
    @Fetch(FetchMode.SELECT)
    private Buku buku;

    public BukuUserPK getBukuUserPk() {
        return bukuUserPk;
    }

    public Date getTanggal_status_buku() {
        return tanggal_status_buku;
    }

    public String getStatusBuku() {
        return statusBuku;
    }

    public void setBukuUserPk(BukuUserPK bukuUserPk) {
        this.bukuUserPk = bukuUserPk;
    }

    public void setTanggal_status_buku(Date tanggal_status_buku) {
        this.tanggal_status_buku = tanggal_status_buku;
    }

    public void setStatusBuku(String statusBuku) {
        this.statusBuku = statusBuku;
    }

    public Integer getRatingBuku() {
        return ratingBuku;
    }

    public void setRatingBuku(Integer ratingBuku) {
        this.ratingBuku = ratingBuku;
    }

    public String getReviewBuku() {
        return reviewBuku;
    }

    public void setReviewBuku(String reviewBuku) {
        this.reviewBuku = reviewBuku;
    }

    public Date getTanggalReviewBuku() {
        return tanggalReviewBuku;
    }

    public void setTanggalReviewBuku(Date tanggalReviewBuku) {
        this.tanggalReviewBuku = tanggalReviewBuku;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Buku getBuku() {
        return buku;
    }

    public void setBuku(Buku buku) {
        this.buku = buku;
    }

    public static final User newInstanceUser(String id) {
        if (MyValidator.validateParam(id)) {
            User user = new User();
            user.setKodeUser(id);

            return user;
        }
        return null;
    }
    
    public static final Buku newInstanceBuku(String id) {
        if (MyValidator.validateParam(id)) {
            Buku buku = new Buku();
            buku.setKodeBuku(id);

            return buku;
        }
        return null;
    }
}
